package com.libraryApp.controller;

import com.libraryApp.appUtil.BeanUtil;
import com.libraryApp.appUtil.Result;
import com.libraryApp.appUtil.ResultGenerator;
import com.libraryApp.appUtil.TokenToUser;
import com.libraryApp.appVo.AppUserInfoVo;
import com.libraryApp.appVo.UserLoginVo;
import com.libraryApp.entity.BookDo;
import com.libraryApp.entity.UserDo;
import com.libraryApp.service.AppUserService;
import com.libraryManage.commons.utils.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @CreateDate 2021-03-07
 * @Author yufang
 */
@Api(tags={"用户信息接口"})
@RestController
@CrossOrigin
@RequestMapping("/app/user")
public class AppUserController {

    @Autowired
    AppUserService appUserService;

    @ApiOperation("获取用户书架")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/bookshelf" , method = RequestMethod.GET)
    public ResponseEntity<List<BookDo>> getBookshelfById(@TokenToUser UserDo userDo){

        return appUserService.getBookshelfById(userDo.getUserId());

    }



//    @ApiOperation("获取用户信息接口")
//    @ApiResponses({
//            @ApiResponse(code=0, message="成功"),
//            @ApiResponse(code=500, message="系统异常"),
//            @ApiResponse(code=999, message="未登录"),
//            @ApiResponse(code=1000, message="数据有效性检查不通过"),
//            @ApiResponse(code=1001, message="业务规则检查不通过")
//    })
//    @RequestMapping(value = "/info" , method = RequestMethod.GET)
//    public Result<AppUserInfoVo> getUserInfo(@TokenToUser UserDo userDo){
//
//        //已登录则直接返回
//        System.out.println(userDo.toString() + "hhhhhhhhhhhhhh");
//        UserLoginVo vo = new UserLoginVo();
//        BeanUtil.copyProperties(userDo, vo);
//        return ResultGenerator.genSuccessResult(vo);
//
//    }

}
